home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Deutsche Edition 1
/
Deutsche Edition 1.iso
/
amok
/
amok_lha
/
amok77.lha
/
GadToolsSupport
/
GadToolsSupport.mod
< prev
next >
Wrap
Text File
|
1993-08-15
|
16KB
|
441 lines
(****************************************************************************
:Program. GadToolsSupport.mod
:Contents. Routines for easy gadget and menu-handling with 2.0 GadTools
:Author. Richard Günther [gvm]
:Address. HeilbronnerStr.267, 7410 Reutlingen
:Phone. 07121/66432
:Copyright. Freeware
:Language. Oberon
:Translator. AmigaOberon v2.14d
:History. V1.0 [gvm] 26-Apr-92 first implementation
:History. V1.1 [gvm] 07-July-92 added menu support, new module name
:Imports. ExecLists [gvm]
:Bugs. Gadget.userData is used by this module, OS2.0 required
****************************************************************************)
MODULE GadToolsSupport ;
IMPORT S : SYSTEM,
O : OberonLib,
E : Exec,
I : Intuition,
G : Graphics,
GT: GadTools,
U : Utility,
EL: ExecLists ;
TYPE WinPtr* = POINTER TO Win;
Win = RECORD (EL.Node)
s : I.ScreenPtr ;
pubLocked : BOOLEAN ;
vInfo : GT.VisualInfo ;
w : I.WindowPtr ;
first : I.GadgetPtr ;
last : I.GadgetPtr ;
firstToAdd : I.GadgetPtr ;
newG : GT.NewGadget ;
waitForDo : BOOLEAN ;
newMenus : POINTER TO ARRAY 1024 OF GT.NewMenu ;
firstFree : INTEGER ;
lastFree : INTEGER ;
endSet : BOOLEAN ;
menu : I.MenuPtr ;
END ;
CONST center* = LONGSET{GT.placeTextIn} ; (* use for NewGadget.textpos *)
right* = LONGSET{GT.placeTextRight} ;
left* = LONGSET{GT.placeTextLeft} ;
above* = LONGSET{GT.placeTextAbove} ; top* = above ;
below* = LONGSET{GT.placeTextBelow} ; down* = below ;
highlight* = LONGSET{GT.highLabel} ;
uChar* = ORD("_") ; (* use for GT.underscore *)
allIDCMP* = LONGSET{I.gadgetUp,I.gadgetDown,I.mouseMove,
I.mouseButtons,I.intuiTicks} ;
TYPE labels1* = ARRAY 2 OF S.ADDRESS ;
labels2* = ARRAY 3 OF S.ADDRESS ; (* use with cycle and mx gadgets to *)
labels3* = ARRAY 4 OF S.ADDRESS ; (* create the labels constants: *)
labels4* = ARRAY 5 OF S.ADDRESS ; (* GA.cyLabels,labels2(S.ADR("one"), *)
labels5* = ARRAY 6 OF S.ADDRESS ; (* S.ADR("two"), *)
labels6* = ARRAY 7 OF S.ADDRESS ; (* NIL) ; *)
labels7* = ARRAY 8 OF S.ADDRESS ;
labels8* = ARRAY 9 OF S.ADDRESS ;
labels9* = ARRAY 10 OF S.ADDRESS ;
labels10* = ARRAY 11 OF S.ADDRESS ; (* I'm shure this is enough *)
CONST none* = LONGSET{} ; (* use for MenuSubItem mExclude *)
mxChecked* = {I.checkIt,I.checked}; (* use the following for Item and *)
mx* = {I.checkIt}; (* SubItem flags *)
toggleChecked* = {I.checkIt,I.menuToggle,I.checked};
toggle* = {I.checkIt,I.menuToggle};
VAR winList : EL.List ;
win : WinPtr ; (* grrrr! *)
int : I.IntuitionBasePtr ;
(* sorry *)
PROCEDURE LockPubScreen{int,-510}(name{8} : S.ADDRESS): I.ScreenPtr ;
PROCEDURE UnlockPubScreen{int,-516}(name{8} : S.ADDRESS ;
screen{9} : I.ScreenPtr) ;
(* call this before using any of the other routines and again after *)
(* a call to Intuition.OpenWindow ! *)
PROCEDURE Init*(VAR win : WinPtr ;
VAR s : I.ScreenPtr ;
w : I.WindowPtr): BOOLEAN ;
BEGIN
IF win#NIL THEN
IF (win.w=NIL) AND (w#NIL) THEN (* if window was opened *)
win.w:=w ;
IF win.firstToAdd#win.first THEN (* gadtools make their own refresh *)
GT.RefreshWindow(win.w,NIL) ;
END ;
ELSIF (win.w#NIL) AND (w=NIL) THEN (* if window was closed *)
win.firstToAdd:=win.first ;
ELSE
RETURN FALSE ; (* what the hell should we do ? *)
END ;
ELSE
NEW(win) ; IF win=NIL THEN RETURN FALSE END ;
IF s=NIL THEN win.s:=LockPubScreen(NIL) ; win.pubLocked:=TRUE
ELSE win.s:=s
END ;
win.vInfo:=GT.GetVisualInfo(win.s,U.done) ;
IF win.vInfo=NIL THEN
DISPOSE(win) ; IF win.pubLocked THEN UnlockPubScreen(NIL,win.s) END ;
RETURN FALSE
END ;
win.first:=GT.CreateContext(win.last) ;
IF win.first=NIL THEN
GT.FreeVisualInfo(win.vInfo) ; DISPOSE(win) ;
IF win.pubLocked THEN UnlockPubScreen(NIL,win.s) END ; RETURN FALSE
END ;
win.w:=w ; win.firstToAdd:=win.first ;
EL.AddHead(winList,win) ;
END ;
RETURN TRUE ;
END Init;
PROCEDURE Dispose*(VAR win : WinPtr) ;
BEGIN
IF win=NIL THEN RETURN END ;
EL.Remove(win) ; (* closedown win *)
GT.FreeGadgets(win.first) ;
IF win.menu#NIL THEN GT.FreeMenus(win.menu) END ;
IF win.newMenus#NIL THEN DISPOSE(win.newMenus) END ;
GT.FreeVisualInfo(win.vInfo) ;
IF win.pubLocked THEN UnlockPubScreen(NIL,win.s) END ;
DISPOSE(win) ;
END Dispose ;
(********************************************************************************)
(************************* NewGadget fill routines ******************************)
(* one of these two procedures is to be called before each call to CreateGadget *)
(* I thought about including this into CreateGadget, but I meant this would *)
(* be better *)
PROCEDURE SpecialNewGadget*(win : WinPtr ;
le,te,wi,he : INTEGER ;
text : S.ADDRESS ;
textpos : LONGSET ;
font : G.TextAttrPtr ;
id : INTEGER) ;
BEGIN
IF win=NIL THEN RETURN END ;
win.newG.leftEdge:=le ; win.newG.topEdge:=te ;
win.newG.width:=wi ; win.newG.height:=he ;
win.newG.gadgetText:=text ;
win.newG.flags:=textpos ;
win.newG.gadgetID:=id ;
win.newG.visualInfo:=win.vInfo ;
IF font=NIL THEN win.newG.textAttr:=win.s.font
ELSE win.newG.textAttr:=font ;
END ;
END SpecialNewGadget ;
(* $CopyArrays- *)
PROCEDURE NewGadget*(win : WinPtr ;
le,te,wi,he : INTEGER ;
text : ARRAY OF CHAR ;
textpos : LONGSET ;
id : INTEGER) ;
BEGIN
IF text="" THEN SpecialNewGadget(win,le,te,wi,he,NIL,textpos,NIL,id)
ELSE SpecialNewGadget(win,le,te,wi,he,S.ADR(text),textpos,NIL,id)
END ;
END NewGadget ;
(********************************************************************************)
(************************* Gadget creation routines *****************************)
(* add all gadgets to be added *)
PROCEDURE AddGadgets(win : WinPtr) ;
BEGIN
IF win.firstToAdd#NIL THEN
IF I.AddGList(win.w,win.firstToAdd,-1,-1,NIL)=0 THEN END ;
I.RefreshGList(win.firstToAdd,win.w,NIL,-1) ;
win.firstToAdd:=NIL ; win.waitForDo:=FALSE ;
GT.RefreshWindow(win.w,NIL) ;
END ;
END AddGadgets ;
(* Sorry for the taglist handling *)
PROCEDURE CreateGadget*{"GadToolsSupport.CG"}(win{8} : WinPtr ;
kind{0} : LONGINT ;
tag1{10}.. : U.Tag
): I.GadgetPtr ;
PROCEDURE CreateGadgetA*{"GadToolsSupport.CG"}(win{8} : WinPtr ;
kind{0} : LONGINT ;
tag1{10} : ARRAY OF U.TagItem
): I.GadgetPtr ;
PROCEDURE CG*(win{8} : WinPtr ;
kind{0} : LONGINT ;
tag{10} : U.TagItemPtr
): I.GadgetPtr ;
VAR g : I.GadgetPtr ;
BEGIN
IF win=NIL THEN RETURN NIL END ;
g:=GT.CreateGadgetA(kind,win.last,win.newG,S.VAL(U.Tags1,tag^)) ;
IF g#NIL THEN
(* GadTools for many gadgettypes creates a group of gadgets, returning *)
(* only the last one. Therefore we need to save the pointer to the first *)
(* because of Remove having to remove and free the whole group ! *)
g.userData:=win.last.nextGadget ; (* first of group *)
IF win.firstToAdd=NIL THEN
win.firstToAdd:=win.last.nextGadget ;
win.last.nextGadget:=NIL ; (* avoid recursieve add *)
END ;
win.last:=g ;
IF NOT win.waitForDo THEN AddGadgets(win) END ;
END ;
RETURN g ;
END CG ;
(* use these procedures instead of orginal gadtools *)
PROCEDURE SetGadgetAttrs*{"GadToolsSupport.SGA"}(win{8} : WinPtr ;
gadget{9} : I.GadgetPtr ;
tag1{10}.. : U.Tag) ;
PROCEDURE SetGadgetAttrsA*{"GadToolsSupport.SGA"}(win{8} : WinPtr ;
gadget{9} : I.GadgetPtr ;
tag1{10} : ARRAY OF U.TagItem) ;
PROCEDURE SGA*(win{8} : WinPtr ;
gadget{9} : I.GadgetPtr ;
tag{10} : U.TagItemPtr) ;
BEGIN
IF (win=NIL) OR (win.w=NIL) OR (gadget=NIL) THEN RETURN END ;
IF win.firstToAdd#NIL THEN AddGadgets(win) END ;
GT.SetGadgetAttrsA(gadget^,win.w,NIL,S.VAL(U.Tags1,tag^)) ;
END SGA ;
(* remove gadget group from intuition-list (not from display !) and free *)
(* its' mem *)
PROCEDURE RemoveGadget*(win : WinPtr ;
gad : I.GadgetPtr) ;
VAR g : I.GadgetPtr ;
cnt : LONGINT ;
BEGIN
IF (win=NIL) OR (gad.userData=NIL) THEN RETURN END ; (* not our gadget *)
IF win.waitForDo THEN AddGadgets(win) END ;
cnt:=1 ;
IF gad.userData#gad THEN
g:=gad.userData ;
WHILE g#gad DO (* we are private owner, so no forbid necessary *)
INC(cnt) ; g:=g.nextGadget ;
END ;
END ;
IF I.RemoveGList(win.w,gad.userData,cnt)=0 THEN END ;
gad.nextGadget:=NIL ; GT.FreeGadgets(gad.userData) ;
END RemoveGadget ;
PROCEDURE DrawBevelBox*{"GadToolsSupport.DBB"}(win{8} : WinPtr;
left{0},top{1} : LONGINT;
width{2},height{3} : LONGINT;
tag{9}.. : U.Tag) ;
PROCEDURE DrawBevelBoxA*{"GadToolsSupport.DBB"}(win{8} : WinPtr;
left{0},top{1} : LONGINT;
width{2},height{3}: LONGINT;
taglist{9} : ARRAY OF U.TagItem) ;
PROCEDURE DBB*(win{8} : WinPtr;
left{0},top{1} : LONGINT;
width{2},height{3}: LONGINT;
taglist{9} : U.TagItemPtr) ;
BEGIN
GT.DrawBevelBoxA(win.w.rPort,left,top,width,height,S.VAL(U.Tags1,taglist^)) ;
END DBB ;
(********************************************************************************)
(*************************** User support routines ******************************)
(* do not add the gadgets yet, but wait for a Do call *)
PROCEDURE WaitForDo*(win : WinPtr) ;
BEGIN
IF win=NIL THEN RETURN END ;
win.waitForDo:=TRUE ;
END WaitForDo ;
(* add and refresh all gadgets added since WaitForDo *)
PROCEDURE Do*(win : WinPtr) ;
BEGIN
IF win=NIL THEN RETURN END ;
AddGadgets(win) ;
END Do ;
(* the following proc is to get the newwindow.firstGadget pointer *)
(* therefore it makes no sense to use this with the window open *)
PROCEDURE FirstGadget*(win : WinPtr): I.GadgetPtr ;
VAR g : I.GadgetPtr ;
BEGIN
IF (win=NIL) OR (win.w#NIL) THEN RETURN NIL END ;
g:=win.firstToAdd ; win.firstToAdd:=NIL ;
win.waitForDo:=FALSE ;
RETURN g ;
END FirstGadget ;
PROCEDURE VInfo*(win : WinPtr): GT.VisualInfo ;
BEGIN
IF win=NIL THEN RETURN NIL
ELSE RETURN win.vInfo
END ;
END VInfo ;
PROCEDURE GetString*( gad : I.GadgetPtr ;
VAR str : ARRAY OF CHAR) ;
BEGIN
COPY(gad.specialInfo(I.StringInfo).buffer^,str) ;
END GetString ;
PROCEDURE GetNumber*(gad : I.GadgetPtr): LONGINT ;
BEGIN
RETURN gad.specialInfo(I.StringInfo).longInt ;
END GetNumber ;
(********************************************************************************)
(*************************** Menu support routines ******************************)
PROCEDURE AllocMenuSpace(win : WinPtr;
count : INTEGER;
new : BOOLEAN) ;
VAR newM : POINTER TO ARRAY 1 OF GT.NewMenu ;
BEGIN
O.New(newM,(count+1)*S.SIZE(GT.NewMenu)) ;
IF new AND (win.newMenus#NIL) THEN
DISPOSE(win.newMenus) ;
win.firstFree:=0 ; win.endSet:=FALSE ;
END ;
IF win.newMenus#NIL THEN
E.CopyMem(win.newMenus[0],newM[0],(win.lastFree+1)*S.SIZE(GT.NewMenu)) ;
END ;
win.newMenus:=S.VAL(S.ADDRESS,newM) ; win.lastFree:=count ;
END AllocMenuSpace ;
PROCEDURE BeginMenus*(win : WinPtr) ;
BEGIN
AllocMenuSpace(win,20,TRUE) ;
END BeginMenus ;
(* $CopyArrays- *)
PROCEDURE NewMenu*(win : WinPtr ;
type : SHORTINT ;
label : S.ADDRESS ;
commKey : ARRAY OF CHAR ;
flags : SET ;
mExclude : LONGSET ;
uData : S.ADDRESS) ;
BEGIN
IF win.firstFree=win.lastFree THEN AllocMenuSpace(win,win.lastFree+10,FALSE) END ;
IF win.endSet THEN DEC(win.firstFree) END ;
win.newMenus[win.firstFree].type:=type ;
win.newMenus[win.firstFree].label:=label ;
IF commKey#"" THEN win.newMenus[win.firstFree].commKey:=S.ADR(commKey) ;
ELSE win.newMenus[win.firstFree].commKey:=NIL ;
END ;
win.newMenus[win.firstFree].flags:=flags ;
win.newMenus[win.firstFree].mutualExclude:=mExclude ;
win.newMenus[win.firstFree].userData:=uData ;
INC(win.firstFree) ;
END NewMenu ;
(* $CopyArrays- *)
PROCEDURE MenuTitle*(win : WinPtr ;
label : ARRAY OF CHAR ;
enabled : BOOLEAN) ;
BEGIN
IF enabled THEN NewMenu(win,GT.title,S.ADR(label),"",{},LONGSET{},NIL) ;
ELSE NewMenu(win,GT.title,S.ADR(label),"",{GT.menuDisabled},LONGSET{},NIL) ;
END ;
END MenuTitle ;
(* $CopyArrays- *)
PROCEDURE MenuItem*(win : WinPtr ;
label : ARRAY OF CHAR ;
commKey : ARRAY OF CHAR ;
flags : SET) ;
BEGIN
NewMenu(win,GT.item,S.ADR(label),commKey,flags,LONGSET{},NIL) ;
END MenuItem ;
PROCEDURE MenuItemBar*(win : WinPtr) ;
BEGIN
NewMenu(win,GT.item,GT.barLabel,"",{},LONGSET{},NIL) ;
END MenuItemBar ;
(* $CopyArrays- *)
PROCEDURE MenuSubItem*(win : WinPtr ;
label : ARRAY OF CHAR ;
commKey : ARRAY OF CHAR ;
flags : SET ;
mExclude : LONGSET) ;
BEGIN
NewMenu(win,GT.sub,S.ADR(label),commKey,flags,mExclude,NIL) ;
END MenuSubItem ;
PROCEDURE DoMenus*(win : WinPtr ;
color : INTEGER): BOOLEAN ;
BEGIN
IF (win.w=NIL) OR (win.newMenus=NIL) OR (win.firstFree=0) THEN RETURN FALSE END ;
IF ~win.endSet THEN
NewMenu(win,GT.end,NIL,"",{},LONGSET{},NIL) ;
win.endSet:=TRUE ;
END ;
IF win.menu#NIL THEN
I.ClearMenuStrip(win.w) ; GT.FreeMenus(win.menu) ; win.menu:=NIL ;
END ;
win.menu:=GT.CreateMenus(win.newMenus^,GT.mnFrontPen,color,U.done) ;
IF win.menu=NIL THEN RETURN FALSE END ;
IF ~GT.LayoutMenus(win.menu,win.vInfo,U.done) THEN
GT.FreeMenus(win.menu) ; win.menu:=NIL ; RETURN FALSE ;
END ;
RETURN I.SetMenuStrip(win.w,win.menu^) ;
END DoMenus ;
PROCEDURE GetMenuAdr*(win : WinPtr): I.MenuPtr ;
BEGIN
RETURN win.menu ;
END GetMenuAdr ;
PROCEDURE NextSelected*(win : WinPtr ;
code : INTEGER): INTEGER ;
VAR item : I.MenuItemPtr ;
BEGIN
item:=I.ItemAddress(win.menu^,code) ;
RETURN item.nextSelect ;
END NextSelected ;
BEGIN
int:=I.int ;
EL.Init(winList) ;
CLOSE
WHILE NOT EL.Empty(winList) DO
win:=S.VAL(WinPtr,EL.Head(winList)) ; (* Dispose removes win from list ! *)
Dispose(win) ;
END ;
END GadToolsSupport.